package tree_util;

import com.common.RequestDataTool;
import com.opensymphony.xwork2.ActionSupport;
import db_tool.DbBean;
import org.apache.struts2.ServletActionContext;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;

public class CheckData  extends ActionSupport {
	private String monitsite;
	private String surface;
	private String line;
	private String dot;
	private String water;
	private String targetMonier;
	private String tool;
	private String catches;
	private String fish;
	private String fishEgg;
	private String zooplankton;
	private String phytoplankton;
	private String benthos;
	private String zooplanktonSpecies;
	private String phytoplanktonSpecies;
	private String benthosSpecies;
	
	private String group;
    public String saveRequest() throws IOException{
    	ServletActionContext.getResponse().setContentType("text/html;charset=utf-8");
        ApplicationContext context = new ClassPathXmlApplicationContext("Spring-Module.xml");
        RequestDataTool requestDataTool = (RequestDataTool) context.getBean("requestDataTool");
        HttpSession session = ServletActionContext.getRequest().getSession();
        Account account = (Account)session.getAttribute("account");
        String name = account.getUsername();
        String [] params = {monitsite,surface,zooplankton,phytoplankton,benthos,line,dot,water,tool,catches
                ,fish,fishEgg,zooplanktonSpecies,phytoplanktonSpecies,benthosSpecies};

        for(int i = 0; i < params.length-1; i++) System.out.println(params[i]+"   ");
        System.out.println("插入Agree表");
        String[]table = {"monitsite","surface","zooplankton","phytoplankton","benthos","line","dot","water"
                ,"tool","catches","fish","fishEgg","zooplanktonSpecies","phytoplanktonSpecies","benthosSpecies"};
        String group1 = requestDataTool.getSuperiorName(name);
        String group2 = requestDataTool.getSuperiorName(targetMonier);
        String same;
        if(group1.equals(group2)){
            same = "1";
        }else{
            same = "0";
        }
        for(int i = 0; i <= params.length-1; i++){
            if(params[i].equals("0")) continue;
            int num = requestDataTool.insertRequest(name, targetMonier, same, table[i], group1, group2);
            System.out.println("插入是否成功"+num);
        }
        return SUCCESS;

    }
    
    public String groupOfMoniter(){
    	 DbBean db = new DbBean();
    	 String result = db.getMoniter(group);
    	  PrintWriter out = null;
    		try {
    			out = ServletActionContext.getResponse().getWriter();
    		} catch (IOException e) {
    			e.printStackTrace();
    		}
    	 System.out.println(result);
    	 out.write(result);
    	return null;
    }
    
    public void setGroup(String group)
    {
    	this.group = group;
    }
    
    public String getGroup()
    {
    	return group;
    }
    
    public void setZooplanktonSpecies(String zooplanktonSpecies){
    	this.zooplanktonSpecies = zooplanktonSpecies;
    }
    
    public String getZooplanktonSpecies(){
    	return zooplanktonSpecies;
    }
    
    public void setPhytoplanktonSpecies(String phytoplanktonSpecies){
    	this.phytoplanktonSpecies = phytoplanktonSpecies;
    }
    
    public String getPhytoplanktonSpecies(){
    	return phytoplanktonSpecies;
    }
    
    public void setBenthosSpecies(String benthosSpecies){
    	this.benthosSpecies = benthosSpecies;
    }
    
    public String getBenthosSpecies(){
    	return benthosSpecies;
    }
    
    public void setBenthos(String benthos){
    	this.benthos = benthos;
    }
    
    public String getBenthos(){
    	return benthos;
    }
    
    public void setPhytoplankton(String phytoplankton){
    	this.phytoplankton = phytoplankton;
    }
    
    public String getPhytoplankton(){
    	return phytoplankton;
    }
    public void setZooplankton(String zooplankton){
    	this.zooplankton = zooplankton;
    }
    
    public String getZooplankton(){
    	return zooplankton;
    }
    
    
    public void setFishEgg(String fishEgg){
    	this.fishEgg = fishEgg;
    }
    
    public String getFishEgg(){
    	return fishEgg;
    }
    
    public void setFish(String fish){
    	this.fish = fish;
    }
    
    public String getFish(){
    	return fish;
    }
	
    public void setTargetMonier(String targetMonier){
    	this.targetMonier = targetMonier;
    }
    
    public String getTargetMonier(){
       return targetMonier;	
    }
    
	public void setMonitsite(String monitsite){
		this.monitsite = monitsite;
	}
	
	public String getMonitsite(){
		return monitsite;
	}
	
	public void setSurface(String surface){
		this.surface = surface;
	}
	
	public String getSurface(){
		return surface;
	}
	
	public void setLine(String line){
		this.line = line;
	}
	
	public String getLine(){
		return line;
	}
	
	public void setDot(String dot){
		this.dot = dot;
	}
	
	public String getDot(){
		return dot;
	}
	
	public void setWater(String water){
		this.water = water;
	}
	
	public String getWater(){
		return water;
	}
	
	public void setTool(String tool){
		this.tool = tool;
	}
	
	public String getTool(){
		return tool;
	}
	
	public void setCatches(String catches){
		this.catches = catches;
	}
	
	public String getCatches(){
		return catches;
	}

}
